package com.beep.erp;

import com.beep.erp.common.bean.LoginBean;
import com.beep.erp.common.bean.UpdateBean;
import com.beep.erp.common.utils.MD5util;
import com.beep.erp.common.utils.TimeUtils;
import com.beep.erp.common.utils.ToolsUtils;
import com.beep.erp.http.HttpRetrofit;
import com.beep.erp.http.RetryWhenNetworkException;
import com.beep.erp.model.home.HomeFragment;
import com.beep.erp.model.login.LoginContract;
import com.beep.erp.model.purchase.BlankFragment;
import com.beep.erp.model.stock.StockFragment;

import java.util.ArrayList;

import rx.Observable;

/**
 * Created by jolly on 2018/8/24.
 */

public class MainModel implements MainContract.Model {

    @Override
    public Observable<UpdateBean> updateVison() {
        long mills = TimeUtils.getCurTimeMills();
        return HttpRetrofit.getInstance().apiService.updateVision(MD5util.MD5Encode(ToolsUtils.getParam(mills)), mills + "").compose(HttpRetrofit.toSubscribe()).compose(HttpRetrofit.toTransformer()).retryWhen(new RetryWhenNetworkException());
    }

    @Override
    public ArrayList<MainBean> getTabs() {
        ArrayList<MainBean> tabs = new ArrayList<>();
        tabs.add(new MainBean(0, R.string.main_tab_name_home, R.drawable.bottom_bar_main_home, HomeFragment.class));
        tabs.add(new MainBean(1, R.string.main_tab_name_order, R.drawable.bottom_bar_main_rank, StockFragment.class));
        return tabs;
    }

    public static class MainBean {
        private int idx;
        private int resName;
        private int resIcon;
        private Class<?> clz;

        MainBean(int idx, int resName, int resIcon, Class<?> clz) {
            this.idx = idx;
            this.resName = resName;
            this.resIcon = resIcon;
            this.clz = clz;
        }

        int getIdx() {
            return idx;
        }

        int getResName() {
            return resName;
        }

        void setResName(int resName) {
            this.resName = resName;
        }

        int getResIcon() {
            return resIcon;
        }

        Class<?> getClz() {
            return clz;
        }
    }
}
